import 'package:flutter/material.dart';
import 'package:hi_flutter/app_page.dart';
import 'package:webview_flutter/webview_flutter.dart';

class FriendPage extends StatelessWidget {
  const FriendPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    WebViewController controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            print("onProgress: $progress");
          },
          onPageStarted: (String url) {
            print("onPageStarted: $url");
          },
          onPageFinished: (String url) {
            print("onPageFinished: $url");
          },
          onWebResourceError: (WebResourceError error) {
            print("onWebResourceError: ${error.description}");
          },
          onNavigationRequest: (NavigationRequest request) {
            if (request.url.startsWith('https://www.youtube.com/')) {
              return NavigationDecision.prevent;
            }
            return NavigationDecision.navigate;
          },
        ),
      )
      ..loadRequest(Uri.parse('https://flutter.cn'));
    return AppPage(
      body: WebViewWidget(
        controller: controller,
      ),
    );
  }
}
